package com.codegenerate.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.codegenerate.demo.entity.AppFun;
import com.codegenerate.demo.mapper.AppFunMapper;
import com.codegenerate.demo.service.AppFunService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;

@Service
public class AppFunServiceImpl extends ServiceImpl <AppFunMapper, AppFun>
        implements AppFunService {


    @Override
    public Boolean exitHaveNext(long id) {
        var query = new QueryWrapper<AppFun>().lambda();
        query.eq(AppFun::getParentId, id);
        var count = this.count(query);
        return count > 0;
    }

    /**
     *  递归获取 所有的 menu数据
     * @return
     */
    @Override
    public List<AppFun> getListAll(long parentId) {
         var query=new QueryWrapper<AppFun>().lambda();
        query.eq(AppFun::getParentId, parentId);
        var menulist = this.list(query);
        if(menulist!=null&&menulist.size()<0){
             return menulist;
        }

        for (int i = 0; i < menulist.size(); i++) {
           var menuone=menulist.get(i);
           if(menuone.getId()<0){
               continue;
           }
           menuone.setChildren(this.getListAll(menuone.getId()));
        }

        return menulist;
    }
}
